home *** CD-ROM | disk | FTP | other *** search
/ Apple II Magazines (PO) / Nibble Volume 12, No. 10 (1991-10)(MindCraft Publishing)(Side A)[a].zip / Nibble Volume 12, No. 10 (1991-10)(MindCraft Publishing)(Side A)[a].po / SETPBUF.ASM.txt < prev    next >
Text File  |  1996-12-24  |  12KB  |  368 lines

  1. **************************************************
  2. *                                                *
  3. *           SETPBUF.ASM Source Listing           *
  4. *               by  Sandy Mossberg               *
  5. *                                                *
  6. *                 APW Assembler                  *
  7. *                                                *
  8. *  Application sets size of printer buffer used  *
  9. *  by serial port firmware. Set your values for  *
  10. *  MyPrtPort and MyBufSize.                      *
  11. *                                                *
  12. *               Copyright (C) 1991               *
  13. *            by MindCraft Publ. Corp.            *
  14. *               Lincoln, MA  01773               *
  15. *                                                *
  16. **************************************************
  17.             mcopy    setpbuf.mac
  18.             keep     setpbuf
  19.  
  20. BZHndl      gequ     $00             ;bank 0 handle
  21. BZPtr       gequ     $04             ;bank 0 ptr
  22. BufHndl     gequ     $08             ;buffer handle
  23. Emulstack   gequ     $010100         ;emulation stack ptr
  24. MyPrtPort   gequ     1               ;printer slot=1
  25. MyBufSize   gequ     $FFFF           ;buffer size=64K
  26.  
  27. *********************************************
  28. *
  29. MainLoop    start
  30. *
  31. * Main program loop:
  32. *
  33. *********************************************
  34.             using    Globals
  35.  
  36.             phk
  37.             plb
  38.             jsr      StartTools      ;startup tools
  39.             jsr      SetBufData      ;set print buffer
  40.             jsr      ShutTools       ;shutdown tools
  41.             _QuitGS  QuitParm
  42.             end
  43.  
  44. *********************************************
  45. *
  46. StartTools  start
  47. *
  48. * Startup tools:
  49. *
  50. *********************************************
  51.             using    Globals
  52.  
  53.             _TLStartUp
  54.  
  55.             pha                result space
  56.             _MMStartUp
  57.             PullWord MasterID  save master ID
  58.  
  59.             _MTStartUp
  60.             rts
  61.             end
  62.  
  63. *********************************************
  64. *
  65. ShutTools   start
  66. *
  67. * Shutdown tools:
  68. *
  69. *********************************************
  70.             using    Globals
  71.  
  72.             _MTShutDown
  73.  
  74.             PushWord MasterID        ;master ID
  75.             _MMShutDown
  76.  
  77.             _TLShutDown
  78.             rts
  79.             end
  80.  
  81. *********************************************
  82. *
  83. SetBufData  start
  84. *
  85. * Set size of serial port printer buffer:
  86. *
  87. *********************************************
  88.             using    Globals
  89.  
  90. ; Reserve bank 0 space for serial port calls:
  91.  
  92.             PushLong #0              ;result space
  93.             PushLong #BZEnd-BZStart  ;size
  94.             PushWord MasterID        ;master ID
  95.             PushWord #$C005          ;attributes
  96.             PushLong #0              ;use bank 0
  97.             _NewHandle
  98.             PullLong BZHndl          ;save handle
  99.             bcc      GetBZPtr        ;no error
  100.             brl      GoErrExit       ;error
  101.  
  102. ; Modify call addresses to bank 0 code:
  103.  
  104. GetBZPtr    lda      [BZHndl]        ;dereference handle
  105.             sta      BZPtr
  106.             sta      GoBZ1+1         ;MODIFY address
  107.             sta      GoBZ2+1         ;MODIFY address
  108.             ldy      #2
  109.             lda      [BZHndl],y
  110.             sta      BZPtr+2
  111.  
  112. ; Modify code to reflect printer's slot ROM:
  113.  
  114.             shortm                   ;8-bit A/memory
  115.             lda      #MyPrtPort      ;slot number
  116.             asl      a               ;move slot to hi nibble
  117.             asl      a
  118.             asl      a
  119.             asl      a
  120.             sta      InitY+1         ;MODIFY address
  121.  
  122.             lda      #$C0
  123.             ora      #MyPrtPort      ;slot ROM address
  124.             sta      InitX+1         ;MODIFY address
  125.             sta      GetInit+2       ;MODIFY address
  126.             sta      GetExtend+2     ;MODIFY address
  127.             sta      DoInit+2        ;MODIFY address
  128.             sta      DoGIB+2         ;MODIFY address
  129.             sta      DoGOB+2         ;MODIFY address
  130.             sta      DoSIB+2         ;MODIFY address
  131.             sta      DoSOB+2         ;MODIFY address
  132.  
  133. ; Modify dispatch addresses (init=Cn0D, extended = Cn12):
  134.  
  135. GetInit     lda      >$C00D          ;MODIFIED
  136.             sta      DoInit+1        ;MODIFY address
  137. GetExtend   lda      >$C012          ;MODIFIED
  138.             sta      DoGIB+1         ;MODIFY address
  139.             sta      DoGOB+1         ;MODIFY address
  140.             sta      DoSIB+1         ;MODIFY address
  141.             sta      DoSOB+1         ;MODIFY address
  142.  
  143. ; Copy image of bank 0 code to bank 0:
  144.  
  145.             ldy      #BZEnd-BZStart-1
  146. CopyLoop    lda      BZStart,y
  147.             sta      [BZPtr],y
  148.             dey
  149.             bpl      CopyLoop
  150.  
  151. ; Invoke serial port calls in bank 0 to get
  152. ; addresses of I/O buffers (pass 1):
  153.  
  154.             long                     ;16-bit regs
  155. GoBZ1       jsl      $001000         ;MODIFIED
  156.  
  157. ; Get attributes and ID of input buffer:
  158.  
  159.             PushLong #0              ;result space
  160.             PushLong GIBBufAdr       ;ptr to memory
  161.             _FindHandle
  162.             PullLong BufHndl         ;inbuf handle
  163.  
  164.             ldy      #4
  165.             lda      [BufHndl],y
  166.             sta      FirmAttrib      ;inbuf attributes
  167.             ldy      #6
  168.             lda      [BufHndl],y
  169.             sta      FirmID          ;inbuf ID
  170.             ldy      #6
  171.  
  172. ; Dispose of handle(s) to I/O buffer memory:
  173.  
  174.             PushLong BufHndl         ;kill handle to inbuf
  175.             _DisposeHandle
  176.  
  177.             PushLong #0              ;result space
  178.             PushLong GOBBufAdr       ;ptr to memory
  179.             _FindHandle              ;outbuf handle
  180.  
  181.             _DisposeHandle           ;kill handle
  182.  
  183. ; Allocate space for new I/O buffers:
  184.  
  185.             PushLong #0              ;result space
  186.             PushLong #MyBufSize      ;size
  187.             PushWord FirmID          ;firmware ID
  188.             PushWord FirmAttrib      ; and attributes
  189.             PushLong #0              ;not used
  190.             _NewHandle
  191.             PullLong BufHndl         ;save handle
  192.             bcs      GoErrExit       ;error
  193.  
  194. ; Set addresses in serial port command lists:
  195.  
  196.             lda      [BufHndl]       ;dereference handle
  197.             sta      SIBBufAdr       ;inbuf lo
  198.             clc                      ;offset to outbuf
  199.             adc      #$800
  200.             sta      SOBBufAdr       ;outbuf lo
  201.             ldy      #2
  202.             lda      [BufHndl],y
  203.             sta      SIBBufAdr+2     ;inbuf hi
  204.             sta      SOBBufAdr+2     ;outbuf hi
  205.             bcc      SetBufLen
  206.             inc      SOBBufAdr+2     ;bump hi word
  207.  
  208. ; Set sizes in serial port command lists:
  209.  
  210. SetBufLen   lda      #800            ;2048 bytes
  211.             sta      SIBBufLen       ;inbuf size
  212.             lda      #MyBufSize-$800
  213.             sta      SOBBufLen       ;outbuf size
  214.  
  215. ; Invoke serial port calls in bank 0 to set
  216. ; addresses of I/O buffers (pass 2):
  217.  
  218. GoBZ2       jsl      $001000         ;MODIFIED
  219.             bra      Exit
  220.  
  221. ; Set error flag and exit:
  222.  
  223. GoErrExit   lda      #-1
  224.             sta      ErrFlag
  225.  
  226. Exit        PushLong BZHndl          ;kill handle to bank 0
  227.             _DisposeHandle
  228.  
  229.             lda      ErrFlag
  230.             beq      Endit           ;no error
  231.  
  232.             _SysBeep                 ;error beep
  233. Endit       rts
  234. ;............................................
  235. ;
  236. ; IMAGE OF BANK ZERO CODE:
  237. ;
  238. ; Save entry environment:
  239.  
  240. BZStart     long                     ;16-bit regs
  241.             phd                      ;save entry direct page
  242.             phb                      ;save entry data bank
  243.             tsc                      ;get stack ptr into
  244.             tax                      ; A,X-regs
  245.             shortm                   ;8-bit A/memory
  246.             xba
  247.             dec      a
  248.             beq      SaveSP          ;stack ptr in page 1
  249.             lda      #1              ;set stack ptr to pg 1
  250.             xba
  251.             lda      Emulstack       ;set emulation mode
  252.             tcs                      ; stack ptr
  253. SaveSP      phx                      ;save entry stack ptr
  254.  
  255. ; Set emulation mode and new environment:
  256.  
  257.             emulation                ;emulation mode
  258.             pea      0
  259.             pld                      ;direct page=page 0
  260.             lda      #0
  261.             pha
  262.             plb                      ;data bank=bank 0
  263.  
  264. ; Check whether to set buffer info:
  265.  
  266.             lda      >BZFlag
  267.             beq      SetSIBAdr       ;it's pass 2
  268.  
  269. ; Initialize serial port firmware on pass 1 (X=Cn, Y=n0):
  270.  
  271. InitX       ldx      #$C0            ;MODIFIED
  272. InitY       ldy      #$00            ;MODIFIED
  273. DoInit      jsr      $C000           ;MODIFIED
  274.             txa                      ;test X-reg
  275.             beq      GetGIBAdr       ;no error
  276.             dc       h'00'           ;crash
  277.  
  278. ; Get buffer info on pass 1:
  279.  
  280. GetGIBAdr   lda      #GIBCmdList     ;point to command list
  281.             ldx      #>GIBCmdList
  282.             ldy      #^GIBCmdList
  283. DoGIB       jsr      $C000           ;MODIFIED
  284.             bcc      GetGOBAdr       ;no error
  285.             dc       h'00'           ;bomb
  286.  
  287. GetGOBAdr   lda      #GOBCmdList     ;point to command list
  288.             ldx      #>GOBCmdList
  289.             ldy      #^GOBCmdList
  290. DoGOB       jsr      $C000           ;MODIFIED
  291.             lda      >BZFlag         ;flag pass 2
  292.             dec      a
  293.             sta      >BZFlag
  294.             bcc      BZRestore       ;no error
  295.             dc       h'00'           ;to monitor
  296.  
  297. ; Set buffer info on pass 2:
  298.  
  299. SetSIBAdr   lda      #SOBCmdList     ;point to command list
  300.             ldx      #>SOBCmdList
  301.             ldy      #^SOBCmdList
  302. DoSIB       jsr      $C000           ;MODIFIED
  303.             bcc      SetSOBAdr       ;no error
  304.             dc       h'00'           ;die hard
  305.  
  306. SetSOBAdr   lda      #SOBCmdList     ;point to command list
  307.             ldx      #>SOBCmdList
  308.             ldy      #^SOBCmdList
  309. DoSOB       jsr      $C000           ;MODIFIED
  310.             bcc      BZRestore       ;no error
  311.             dc       h'00'           ;arrrggh!
  312.  
  313. ; Restore entry environment:
  314.  
  315. BZRestore   native   long            ;full native mode
  316.             plx                      ;restore entry stack ptr
  317.             txs
  318.             plb                      ;restore entry data bank
  319.             pld                      ;restore entry direct page
  320.             rtl
  321. BZEnd       anop
  322.             end
  323.  
  324. *********************************************
  325. *
  326. Globals     data
  327. *
  328. * Global data:
  329. *
  330. *********************************************
  331.  
  332. QuitParm    dc  i2'0'                ;pCount = 0
  333. MasterID    ds  2                    ;application ID
  334. FirmAttrib  ds  2                    ;firmware attributes
  335. FirmID      ds  2                    ;firmware ID
  336. ErrFlag     dc  i2'0'                ;0=no error, -1=error
  337. BZFlag      dc  i1'1'                ;1=pass 1=init/get info
  338. ;                                    ;0=pass 2=set info
  339.  
  340. GIBCmdList  anop                     ;GetInBuffer command list
  341.             dc  h'04'                ;pCount = 4
  342.             dc  h'10'                ;command code
  343.             ds  2                    ;return code
  344. GIBBufAdr   ds  4                    ;buffer address
  345. GIBBufLen   ds  2                    ;buffer length
  346.  
  347. GOBCmdList  anop                     ;GetOutBuffer command list
  348.             dc  h'04'                ;pCount = 4
  349.             dc  h'11'                ;command code
  350.             ds  2                    ;return code
  351. GOBBufAdr   ds  4                    ;buffer address
  352. GOBBufLen   ds  2                    ;buffer length
  353.  
  354. SIBCmdList  anop                     ;SetInBuffer command list
  355.             dc  h'04'                ;pCount = 4
  356.             dc  h'12'                ;command code
  357.             ds  2                    ;return code
  358. SIBBufAdr   ds  4                    ;buffer address
  359. SIBBufLen   ds  4                    ;buffer length
  360.  
  361. SOBCmdList  anop                     ;SetOutBuffer command list
  362.             dc  h'04'                ;pCount = 4
  363.             dc  h'13'                ;command code
  364.             ds  2                    ;return code
  365. SOBBufAdr   ds  4                    ;buffer address
  366. SOBBufLen   ds  4                    ;buffer length
  367.             end
  368.